﻿#include "tables.h"

void QualityAlarm::CheckAlarm(float temp, float hum){
    if(!param && param->serialName.isEmpty()) return;//指针不为空且指针指向的code为空

    if(this->type == 0){
        this->CheckTemp(temp);
    }else if(this->type == 1){
        this->CheckHum(hum);
    }
}

void QualityAlarm::CheckTemp(float temp){
#if 0
    if(save == 1) save = 2;     //如果已经保存报警状态则改成2

    QDateTime nowDateTime   = QDateTime::currentDateTime();
    long  firsttime         = startDate.secsTo(nowDateTime);
    //float threshold         = param->tempThreshold;
    //int   alarmtime         = param->tempTime;

    endDate = QDateTime::currentDateTime();

    if(temp < threshold){ //没有达到门限
        if(save != 0){      //已经报警则解除
            relieve = 1;
            save = 3;
            return;
        }else{              //开始时间设置为当前时间
            relieve = -1;
            startDate  = QDateTime::currentDateTime();
        }
    }else{
        if(firsttime > alarmtime && save == 0){ //如果大于 报警时间 并且没有保存 则保存
            relieve = 0;
            save = 1;
        }
    }
    value = temp;
#endif
}

void QualityAlarm::CheckHum(float hum){
#if 0
    if(save == 1) save = 2;     //如果已经保存报警状态则改成2

    QDateTime nowDateTime   = QDateTime::currentDateTime();
    long  firsttime         = startDate.secsTo(nowDateTime);
    //float threshold         = param->humThreshold;
    //int   alarmtime         = param->humTime;

    endDate = QDateTime::currentDateTime();

    if(hum < threshold){ //没有达到门限
        if(save != 0){      //已经报警则解除
            relieve = 1;
            save = 3;
            return;
        }else{              //开始时间设置为当前时间
            relieve = -1;
            startDate  = QDateTime::currentDateTime();
        }
    }else{
        if(firsttime > alarmtime && save == 0){ //如果大于 报警时间 并且没有保存 则保存
            relieve = 0;
            save = 1;
        }
    }
    value = hum;
#endif
}

